﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTOFrameworks;
using System.Data;
using PhysicalDataProvider;
/*
namespace FAQFrameworks
{
    public class ForumDataTableVisitor : ITreeVisitor<Forum>, ITreeVisitor
    {
        public static ITreeVisitor<Forum> CreateVisitor()
        {
            ForumDataTableVisitor visitor
                = new ForumDataTableVisitor
                    (DataService.FillTable
                    ("SELECT * FROM t_Forums"));

            return visitor;
        }

        public ForumDataTableVisitor(DataTable dt)
        {
            dv = new DataView(dt);
            dv.Sort = "ParentId";

            index = GetIndexByParentId(0);

        }

        int GetIndexByParentId(int id)
        {
            int result = -1;

            for (int i = 0; i < dv.Count; i++)
            {
                DataRowView drv = dv[i];

                if (drv["ParentId"].Equals(id))
                {
                    result = i;
                    break;
                }
            }

            return result;
        }

        int GetIndexById(int id)
        {
            int result = -1;

            for (int i = 0; i < dv.Count; i++)
            {
                DataRowView drv = dv[i];

                if (drv["ForumId"].Equals(id))
                {
                    result = i;
                }
            }

            return result;
        }

        DataView dv;

        int index = 0;

        #region ITreeVisitor<Forum> 成员

        public bool MoveTo(Forum f)
        {
            int newIndex = GetIndexById(f.ForumId);

            if (newIndex < 0)
            {
                return false;
            }

            index = newIndex;

            return true;
        }

        public bool MoveUp()
        {
            int parentId = (int)dv[index]["ParentId"];
            if (parentId != 0)
            {
                int newIndex = GetIndexById(parentId);
                if (newIndex > 0)
                {
                    index = newIndex;
                    return true;
                }
            }

            return false;
        }

        public bool MoveNext()
        {
            int newIndex = index + 1;
            if (newIndex < dv.Count)
            {
                int preParentId = (int)dv[index]["ParentId"];
                int parentId = (int)dv[newIndex]["ParentId"];
                if (parentId == preParentId)
                {
                    index = newIndex;

                    return true;
                }
            }

            return false;
        }

        public bool MoveFirstChild()
        {
            int currentId = (int)dv[index]["ForumId"];
            int newIndex = GetIndexByParentId(currentId);
            if (newIndex > 0)
            {
                index = newIndex;

                return true;
            }

            return false;
        }

        public Forum GetValue()
        {
            Forum f = new Forum();
            f.ForumId = (int)dv[index]["ForumId"];
            f.ForumName = (string)dv[index]["ForumName"];

            return f;
        }

        #endregion

        #region ITreeVisitor 成员


        object ITreeVisitor.GetValue()
        {
            return this.GetValue();
        }

        public bool MoveTo(object t)
        {
            return this.MoveTo(t);
        }

        #endregion
    }
}
*/